package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.Area;
import cn.poco.pepsi.bean.OnHere;

public class OnHereXmlparse {
	//private final static String TAG = "DisAreaXmlparse";
	private static ArrayList<OnHere> onhs = null;
	private static  OnHere onhBean = null;
	
	public static ArrayList<OnHere> getXml(InputStream inSteam) throws Exception{
		XmlPullParser xmpparse = Xml.newPullParser();   //寰楀埌瑙ｉ噴鍣�
		xmpparse.setInput(inSteam, "UTF-8");           //璁剧疆瑙ｉ噴娴�
		int code = xmpparse.getEventType();            //寰楀埌鑺傜偣淇℃伅
		while(code!=XmlPullParser.END_DOCUMENT){
			switch (code) {
			case XmlPullParser.START_DOCUMENT:
				onhs = new ArrayList<OnHere>();
				break;
			case XmlPullParser.START_TAG:
				if("item".equals(xmpparse.getName())){
					onhBean = new OnHere();
				}
				if(onhBean!=null){
					if("res-id".equals(xmpparse.getName())){
						String key = xmpparse.nextText();
						onhBean.setResid(key);
					}
					if("res-name".equals(xmpparse.getName())){
						String name = xmpparse.nextText();
						onhBean.setResname(name);
					}
					if("user-id".equals(xmpparse.getName())){
						String next = xmpparse.nextText();
						
						onhBean.setUserid(next);
					}
					if("user-name".equals(xmpparse.getName())){
						String next = xmpparse.nextText();
						
						onhBean.setUsername(next);
					}
					if("timestamp".equals(xmpparse.getName())){
						String next = xmpparse.nextText();
						onhBean.setTimestamp(next);
					}
				}
				break;
			case XmlPullParser.END_TAG:
				if("item".equals(xmpparse.getName())){
					onhs.add(onhBean);
					onhBean = null;
				}
				break;
			}	
			code = xmpparse.next();
		}
		inSteam.close();
		return onhs;
	}
}
